package tech.aistar.mapper.notecom;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tech.aistar.entity.notecom.Com;

import java.util.List;


/**
 * Created by Administrator on 2019/10/7.
 */
public interface ComMapper {

    @Select("select * from comment")
    List<Com> findAllComment();

    @Select("select * from comment where note_id = #{note_id}")
    List<Com> findAllByNoteId(Integer noteId);

    //根据评论id查询评论
    @Select("select * from comment where com_id = #{comId}")
    Com findComByComId(Integer comId);

    /**
     * 查询帖子一级评论
     */
    @Select("select * from comment where note_id = #{note_id} and flag = 1")
    List<Com> findOneComment(Integer noteId);

    //查询所有评论数
    @Select("select count(*) from comment")
    Integer findAllComNum();

    //查询帖子下一级评论数
    //flag在SendCom中赋值
    @Select("select count(*) from comment where note_id = #{note_id} and flag = 1")
    Integer findOneComNum(Integer noteId);

    //显示所有层评论下的所有二级评论
    @Select("select * from comment where floor = #{floor} and note_id = #{note_id} and flag = 2")
    List<Com> findAllTwoComment(@Param("floor") Integer floor, @Param("note_id") Integer noteId);

    //显示该层评论下的所有二级评论
    @Select("select * from comment where flag = #{flag} and floor = #{floor} and note_id = #{note_id}")
    List<Com> findTwoComment(@Param("floor") Integer floor, @Param("flag") Integer flag, @Param("note_id") Integer noteId);

    //每层一级评论下二级评论个数
    //评论点赞数

    //根据评论者查询所有
    @Select("select * from comment where user_id = #{userId}")
    Integer findAllByUserId(Integer userId);
    //根据被评论者查询所有
    @Select("select * from comment where to_user_id = #{toUserId}")
    Integer findAllByToUserId(Integer toUserId);

    /**
     * 插入评论
     */
    @Insert("insert into comment(floor,note_id,user_id,to_user_id,content,ctime,point_num,flag) values(#{floor},#{noteId},#{userId},#{toUserId},#{content},#{ctime},#{pointNum},#{flag})")
    void saveComment(Com com);


}
